package com.uphone.kingmall.activity.personal;

import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.china.zhuoyue.R;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.base.BaseBean;
import com.uphone.kingmall.listener.onNormalRequestListener;
import com.uphone.kingmall.utils.GsonUtils;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.OkGoUtils;
import com.uphone.kingmall.utils.ToastUtils;
import com.uphone.kingmall.utils.intent.IntentData;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * <pre>
 *     author : radish
 *     e-mail : 15703379121@163.com
 *     time   : 2019/3/18
 *     desc   :
 * </pre>
 */
public class ShopComplainActivity extends BaseActivity {
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.btn_commit)
    Button btnCommit;

    @IntentData
    private int id;

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_complain;
    }

    @Override
    public void initView() {
        setStatusBar();
    }

    @Override
    public void initData() {
    }

    @OnClick({R.id.iv_back, R.id.btn_commit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_commit:
                complainShop();
                break;
        }
    }


    private void complainShop() {
        // 加载网络数据
        if (TextUtils.isEmpty(etContent.getText().toString())) {
            ToastUtils.showShortToast(this, "请输入您的意见");
            return;
        }
        HttpParams params = new HttpParams();
        params.put("itemId", id);
        params.put("repReason", etContent.getText().toString().trim());
        //投诉店铺
        OkGoUtils.progressRequest(MyUrl.reportShop, this, params, new onNormalRequestListener() {


            @Override
            public void onSuccess(String body, int code) {
                BaseBean bean = GsonUtils.getGson().fromJson(body, BaseBean.class);
                if (bean.getCode() == 0) {
                    ToastUtils.showShortToast(ShopComplainActivity.this, "投诉成功");
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            finish();
                        }
                    }, 500);
                }
            }

            @Override
            public void onError(Response<String> response) {

            }
        });
    }
}
